//
//  XWHLargeTitleView.swift
//  XiaoweHealthy
//
//  Created by Riven on 2022/4/19.
//

import UIKit

class XWHLargeTitleView: XWHBaseView {
    
    typealias LayoutHandler = (XWHLargeTitleView) -> Void

    lazy var titleLb = UILabel()
    lazy var detailLb = UILabel()
    lazy var button = UIButton()
    
    var clickButtonAction: (() -> Void)?
    
    override func addSubViews() {
        addSubview(titleLb)
        addSubview(detailLb)
        addSubview(button)

        titleLb.font = navTitleFont
        titleLb.textColor = majorTextColor
        titleLb.textAlignment = .left
        titleLb.adjustsFontSizeToFitWidth = true
        titleLb.baselineAdjustment = .alignBaselines
        
        detailLb.font = AppFont.harmonyOSSans(ofSize: 15, weight: .medium)
        detailLb.textColor = minorTextColor
        detailLb.textAlignment = .left
        detailLb.adjustsFontSizeToFitWidth = true
        detailLb.isHidden = true
        
        button.titleLabel?.font = AppFont.harmonyOSSans(ofSize: 16, weight: .medium)
        button.titleLabel?.adjustsFontSizeToFitWidth = true
//        button.contentHorizontalAlignment = .right
        button.setTitleColor(majorTextColor, for: .normal)
        
        button.addTarget(self, action: #selector(clickButton), for: .touchUpInside)
    }
    
    @objc func clickButton() {
        clickButtonAction?()
    }
    
    override func relayoutSubViews() {
        relayoutNormal()
    }
    
    @objc func relayoutNormal() {
        relayout(leftRightInset: 28)
    }
    
    @objc func relayout(leftRightInset: CGFloat) {
        titleLb.snp.remakeConstraints { make in
            make.top.equalToSuperview()
            make.height.equalTo(40)
            make.left.right.equalToSuperview().inset(leftRightInset)
        }
    }
    
    @objc func relayout(_ layoutHandler: LayoutHandler) {
        layoutHandler(self)
    }

}
